<template>
    <section>
        <the-dialog :cfg="cfg" width="80%" defined-footer @closed="onClose()">
            <div class="hospital-popup" slot="body">
                <el-form class="x-form" ref="oForm" :model="form" :rules="formRule" size="small" label-width="120px">
                    <el-form-item label="姓名：">
                        {{info.patientName}}
                    </el-form-item>
                    <el-form-item label="身份证号：">
                        {{info.patientIdcard}}
                    </el-form-item>
                    <el-form-item label="性别：">
                        {{info.patientSex == 0 ? '女':'男'}}
                    </el-form-item>
                    <el-form-item label="联系方式：">
                        {{info.patientPhone}}
                    </el-form-item>
                    <el-form-item label="出生日期：">
                        {{info.patientBirthday}}
                    </el-form-item>
                    <el-form-item label="主要症状：">
                        {{info.mainSuit}}
                    </el-form-item>
                    <el-form-item label="初步诊断：">
                        {{info.diagnosisDescribe}}
                    </el-form-item>
                    <el-form-item label="建议：" prop="hospitalizationDepartment">
                        <span class="tips">因病情需要，请前往{{info.hospitalName}}</span>
                        <el-input v-model="form.hospitalizationDepartment" placeholder="请输入科室"></el-input>
                        <span>，办理住院</span>
                    </el-form-item>
                    <el-form-item label="备注：" prop="remark">
                        <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" :rows="5" maxlength="200" show-word-limit resize="none"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div slot="foot">
                <el-button class="o-btn" type="primary" @click="onSubmit">确认生成</el-button>
            </div>
        </the-dialog>
    </section>
</template>

<script>
    export default {
        data() {
            return {
                cfg: {
                    visible: false,
                    title: '住院建议书',
                    titieTips: '* 请认真确认信息，以免影响用户入院'
                },
                loading: false,

                logId: '',
                info: {},
                form: {
                    hospitalizationDepartment: '',
                    remark: ''
                },
                formRule: {
                    hospitalizationDepartment: [{ required: true, message: '科室不能为空', trigger: 'blur' }]
                }
            }
        },
        methods: {
            onOpen({ logId, data } = {}) {
                /* data:患者信息资料 */

                this.cfg.visible = true;
                this.logId = logId;
                this.info = data || {};
            },
            onClose(flag) {
                this.cfg.visible = false;
                this.loading = false;

                Object.assign(this.$data, this.$options.data.call(this));
                this.$emit('closed', flag)
            },
            onSubmit() {
                this.loading = true;

                this.$refs.oForm.validate(valid => {
                    if (valid) {
                        let params = {
                            logId: this.logId,
                            ...this.form
                        }

                        this.$ajax.addInquiryLogHospitalization(params).then(res => {
                            this.$util.message(res.msg, 'success')
                            this.onClose(true)
                        }).catch(err => {
                            this.loading = false;
                            this.$util.message(err.msg)
                        })
                    } else {
                        this.loading = false;
                    }
                })
            }
        }
    }
</script>

<style>
    .hospital-popup {}
</style>